package controller

import (
	"gitee.com/zhoulvvv/my_go_gateway/middleware"
	"gitee.com/zhoulvvv/my_go_gateway/services"
	"github.com/gin-gonic/gin"
)

type DashBoardController struct {
	DashBoardSvc *services.DashBoardService
}

func RegisterDashBoardController(group *gin.RouterGroup) {
	dashboard := &DashBoardController{}
	dashboardService, err := services.NewDashBoardService()
	if err != nil {
		panic("首页大盘Service初始化失败：" + err.Error())
	}
	dashboard.DashBoardSvc = dashboardService
	group.GET("/panel_group_data", dashboard.PanelGroupData) // 指标统计
	group.GET("/flow_stat", dashboard.FlowStat)              // 流量统计
	group.GET("/service_stat", dashboard.ServiceStat)        // 服务统计
}

// ServiceStat godoc
// @Summary 服务统计
// @Description 服务统计
// @Tags 首页大盘
// @ID /dashboard/service_stat
// @Accept  json
// @Produce  json
// @Success 200 {object} middleware.Response{data=dto.PanelServiceStatOutput} "success"
// @Router /dashboard/service_stat [get]
func (d *DashBoardController) ServiceStat(c *gin.Context) {
	// 查询服务类型数量
	out, err := d.DashBoardSvc.ServiceStat(c)
	if err != nil {
		middleware.ResponseError(c, 5000, err)
		return
	}
	middleware.ResponseSuccess(c, out)
}

// PanelGroupData godoc
// @Summary 指标统计
// @Description 指标统计
// @Tags 首页大盘
// @ID /dashboard/panel_group_data
// @Accept  json
// @Produce  json
// @Success 200 {object} middleware.Response{data=dto.PanelGroupDataListOutput} "success"
// @Router /dashboard/panel_group_data [get]
func (d *DashBoardController) PanelGroupData(c *gin.Context) {
	// 查询指标
	out, err := d.DashBoardSvc.PanelGroupData(c)
	if err != nil {
		middleware.ResponseError(c, 5000, err)
		return
	}
	middleware.ResponseSuccess(c, out)
}

// FlowStat godoc
// @Summary 流量统计
// @Description 流量统计
// @Tags 首页大盘
// @ID /dashboard/flow_stat
// @Accept  json
// @Produce  json
// @Success 200 {object} middleware.Response{data=dto.PanelStatOutput} "success"
// @Router /dashboard/flow_stat [get]
func (d *DashBoardController) FlowStat(c *gin.Context) {
	// 流量统计
	out, err := d.DashBoardSvc.FlowStat(c)
	if err != nil {
		middleware.ResponseError(c, 5000, err)
		return
	}
	middleware.ResponseSuccess(c, out)
}
